package com.love_weinuo.ui.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.lzy.okgo.callback.StringCallback;
import com.love_weinuo.R;
import com.love_weinuo.databinding.ActivityChangeNicknameBinding;
import com.love_weinuo.ui.BaseActivity;
import com.love_weinuo.util.HTTPAPI;
import com.love_weinuo.util.LogUtil;
import com.love_weinuo.util.SpUtils;
import com.love_weinuo.util.ToastUtil;

import okhttp3.Call;
import okhttp3.Response;

/**
 * Created by SensYang on 2019/03/01 13:42
 */

public class ChangeNickNameActivity extends BaseActivity {

    ActivityChangeNicknameBinding binding;
    String userId = (String) SpUtils.get("module_user_id", "");

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_change_nickname);
        binding.setActivity(this);
        initView();
    }


    private void initView() {
        add(this);
        setBack();
        setTitleText("修改昵称");

        binding.ivModuleDelete.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivModuleDelete:
                binding.etModuleNickname.setText("");
                break;
            case R.id.textViewMain:
                String nickName = binding.etModuleNickname.getText().toString().trim();
                if (TextUtils.isEmpty(nickName)) {
                    ToastUtil.showToast("请输入昵称");
                    return;
                }
                HTTPAPI.getInstance().updataNickName(userId, nickName, new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        LogUtil.e("昵称更新成功" + s);
                        showInCommonDialog("修改成功");
                        finish();
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        LogUtil.e("昵称更新失败" + e.getMessage());
                    }
                });
                break;
            default:
        }
    }
}
